package com.moneywelcome.gateway.util;


/**
 * 统一返回结果
 * @param <T> 返回数据的类型
 */
public class Result<T> {

    private boolean success;

    private String code;

    private String message;

    private T data;

    public Result() {
    }

    public Result(boolean success, String code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result getInstance(){
        return new Result();
    }

    public static Result success(){
        return success(null);
    }

    public static Result success(Object data){
        return success("EXECUTE_SUCCESS","执行成功",data);
    }

    public static Result success(String code,String message,Object data){
        return new Result(true,code,message,data);
    }

    public static Result fail(){
        return fail("执行失败");
    }

    public static Result fail(String message){
        return fail("EXECUTE_FAIL",message);
    }

    public static Result fail(String code,String message){
        return new Result(false,code,message,null);
    }


    public boolean isSuccess() {
        return success;
    }

    public Result setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public String getCode() {
        return code;
    }

    public Result setCode(String code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return "Result{" +
                "success=" + success +
                ", code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
